package mujmail;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Anup.s
 */
import java.util.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
public class Logger {
private  static DataOutputStream dos;
private static FileConnection fc;
private static boolean enableLog=false;
private static boolean  enableFileLog=false;
    static{
        enableFileLog=false;//(System.getProperty("microedition.platform").equals("SunMicrosystems_wtk"))?false:true;
      if(enableFileLog)
      {
       String s=  new Date().toString().replace(' ', '_').replace(':', '_').substring(4);
       String url="file:///other/"+s+".txt";
       try{
           System.out.println("URL IS"+url);
           FileConnection  fc1 = (FileConnection)Connector.open("file:///other/Test.txt");
           if(fc1.exists())
               fc1.delete();
           fc1.create();
           fc1.close();
           fc = (FileConnection)Connector.open("file:///other/log.txt");
           if(fc.exists())
               fc.delete();
           fc.create();
           dos= fc.openDataOutputStream();
       }
       catch(Exception e)
       {
           enableFileLog=false;
           e.printStackTrace();
       }
      }
    }
    public static void log(String s)
    {
        if(enableFileLog)
            LogToFile(s);
       if(enableLog)
        System.out.println(s);

    }
    public static void close()
    {  if(!enableFileLog)
        return;
        try{
            dos.close();
            fc.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    private static void LogToFile(String s)
    {
        try{
            dos.writeUTF(s);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}
